<!DOCTYPE html>
<html>
<head>
<title>${context.getContextName()}</title>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no"/>
${Styles.src(zhiqim.mobile.css)}
${Scripts.src(zhiqim.mobile.js)}
${Scripts.src(jsencrypt.js)}
<style>
.z-bar-top{background-color:#00a2eb;}
</style>
<script>
Z.onload(function()
{//默认焦点
    if (Z("#operatorCode").val() == "")
        Z("#operatorCode").focus();
    else if (Z("#operatorPass").val() == "")
        Z("#operatorPass").focus();
    else if (Z("#verificationCode").val() == null)
        Z("#verificationCode").focus();
    else
        Z("#operatorCode").focus();
        
    Z(document).keydown(function(e)
    {
        if (Z.E.key(e) != Z.E.KEY.ENTER)
            return;
            
        if (!Z.Dialog.cache.isEmpty())
            return;
            
        doLogin();
    });
});

function doRememberCode(rememberCode)
{//取消记住账号时，同时取消记住密码
    if (!rememberCode.checked)
    {
        Z("#rememberPass")[0].checked = false;
        Z("[data-id=rememberPass]").removeClass("z-active");
    }
}

function doRememberPass(rememberPass)
{//记住密码时，同时记住账号
    if (rememberPass.checked)
    {
        Z("#rememberCode")[0].checked = true;
        Z("[data-id=rememberCode]").addClass("z-active");
    }
}

function doLogin()
{//ajax登陆
    var operatorCode = Z("#operatorCode").val();
    if (Z.V.isEmptyBlank(operatorCode))
    {//账号和密码必填
        Z.failure("账号不能为空！");
        Z("#operatorCode").focus();
        return;
    } 
    
    var operatorPass = Z("#operatorPass").val();
    if (Z.V.isEmptyBlank(operatorPass))
    {//账号和密码必填
        Z.failure("密码不能为空！");
        Z("#operatorPass").focus();
        return;
    } 
    
    var verificationCode = Z("#verificationCode").val();
    if (Z("#verificationCode").length > 0 && verificationCode.length != 4)
    {//如果有验证码框的时候，要求值必须是4位（数字在输入时控制）
        Z.failure("验证码为4位数字！");
        return;
    }
    
    //对密码进行RSA加密
    var publicKey = "${ZmrParamDao.getPublicKey()}";
    var encrypt = new JSEncrypt();
    encrypt.setPublicKey(publicKey);
    operatorPass = encrypt.encrypt(operatorPass);
    
    var ajax = new Z.Ajax();
    ajax.setContextPath("${context.getContextPath()}");
    ajax.setClassName("ZmrLoginPresenter");
    ajax.setMethodName("doLogin");
    ajax.addParam("operatorCode", operatorCode);
    ajax.addParam("operatorPass", operatorPass);
    
    <#if hasRememberPass>
    if (Z("#rememberPass")[0].checked)
        ajax.addParam("rememberPass", rememberPass);
    </#if>
    <#if hasRememberCode>
    if (Z("#rememberCode")[0].checked)
        ajax.addParam("rememberCode", rememberCode);
    </#if>
    
    ajax.addParam("verificationCode", verificationCode);
    ajax.setFailureAlert();
    ajax.setSuccess(function(){window.location.href= this.responseText;});
    ajax.execute();
}
</script>
</head>

<body>
<!-- 顶部导航 -->
<div class="z-bar-top zi-bd-none">
    <div class="z-relative-left z-pd-l10 z-rem18 z-color-white">${context.getContextName()}</div>
</div>

<!-- 容器内 -->
<div class="z-container" style="margin-bottom:.5rem;">
<form action="javascript:void(0);" class="z-pd15">
    <input type="text" class="z-hidden-fixed">
    <input type="password" class="z-hidden-fixed">
    <ul class="z-input-list">
        <li><input id="operatorCode" class="z-w100p input" placeholder="账号" value="#{operatorCode}" maxlength="16" spellcheck="false" autocomplete="off"></li>
        <li><input id="operatorPass" type="password" class="z-w100p input" placeholder="密码" value="#{operatorPass}" maxlength="16" spellcheck="false" autocomplete="off"></li>
        <#if hasVerificationCode>
        <li>
            <input id="verificationCode" class="input verificationCode" style="width:270px" placeholder="验证码" data-options="type:Numeric;paste:true;" maxlength="4" spellcheck="false" autocomplete="off">
            <img class="z-pointer z-bd-rd5 z-mg-t-6" title="点击刷新验证码" onclick="this.src='service/vcode.jpg?bgColor=%231299ec&width=120&height=50&fontSize=20&yawp=true&t='+new Date().getTime();" src="service/vcode.jpg?bgColor=%231299ec&width=120&height=50&fontSize=20&yawp=true&t=${DateTimes.getDateTime17String()}">
        </li>
        </#if>
        <#if hasRememberCode>
        <li>
        <div class="z-w100p">
            <input id="rememberCode" type="checkbox" class="z-checkbox z-small" onclick="doRememberCode(this);" <#if Validates.isNotEmpty(operatorCode)>checked</#if>>&nbsp;&nbsp;记住账号
            <#if hasRememberPass>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input id="rememberPass" type="checkbox" class="z-checkbox z-small" onclick="doRememberPass(this);" <#if Validates.isNotEmpty(operatorPass)>checked</#if>>&nbsp;&nbsp;记住密码
            </#if>
        </div>
        </li>
        </#if>
    </ul>
    <div class="z-pd20"></div>
    <button type="button" class="z-button-flex z-blue" onclick="doLogin()">登&nbsp;&nbsp;录</button>
</form>
</div>
<div class="z-bar-bottom z-pd10 zi-pd-t15">${zmr_copyright}</div>
</body>
</html>